module.exports = function(app) {
  var treesfixtures = require('../fixtures/trees');
  var express = require('express');
  var treesRouter = express.Router();

  var generatedId = 10000;

  treesRouter.get('/', function(req, res) {
    var id = req.query.id;
    if (id) {
      res.json(treesfixtures.find(id));
    } else {
      res.json(treesfixtures.listResponse);
    }
  });

  treesRouter.put("/:id/update", function(req, res){
    var id = req.params.id;
    res.json(treesfixtures.updateOne(id, req.body.tree));
  });

  treesRouter.post('/', function(req, res) {
    res.status(201).json(treesfixtures.createNew(req.body.tree));
  });

  treesRouter.put('/:id', function(req, res) {
    res.send({
      'roles': {
        id: req.params.id
      }
    });
  });

  treesRouter.delete('/:id', function(req, res) {
    res.status(204).end();
  });

  app.use('/api/v1/trees', require('body-parser').json(), treesRouter);
};
